package com.huanuo.internetofthings.service.jasperStatus;

import com.huanuo.internetofthings.bo.jasperStatus.JasperStatus;
import com.huanuo.internetofthings.bo.jasperStatus.JasperStatusExample;
import com.huanuo.internetofthings.dao.jasperStatus.JasperStatusMapper;
import com.huanuo.internetofthings.dto.jasperStatus.JasperStatusPageRequestDto;
import org.springframework.stereotype.Service;
import org.unicorn.framework.base.base.AbstractService;
import org.unicorn.framework.core.exception.PendingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.unicorn.framework.core.SysCode;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiebin
 * @since 2018-08-16
 */
@Service
public class JasperStatusService extends AbstractService {

  @Autowired
  private JasperStatusMapper jasperStatusMapper;
    /**
     * 根据主键删除记录
     * @param id
     * @return
     * @throws PendingException
     */
  public void deleteByPrimaryKey(Integer id) throws PendingException{
        try {
			 jasperStatusMapper.deleteByPrimaryKey(id);
		} catch (Exception e) {
			error("删除记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "删除记录失败");
	    }
  }

    /**
     * 根据Example删除记录
     * @param jasperStatusExample
     * @return
     * @throws PendingException
     */
  public void deleteByExample(JasperStatusExample jasperStatusExample ) throws PendingException{
       try {
			 jasperStatusMapper.deleteByExample(jasperStatusExample);
		} catch (Exception e) {
			error("根据Example删除记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据Example删除记录失败");
	    }
    
  }


   /**
     * 保存记录
     * @param jasperStatus
     * @return
     * @throws PendingException
     */
   public  JasperStatus save(JasperStatus jasperStatus) throws PendingException{
       try {
			 jasperStatusMapper.insertSelective(jasperStatus);
			 return jasperStatus;
		} catch (Exception e) {
			error("新增记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "新增记录失败");
	    }
   }
   
    /**
     * 批量保存记录
     * @param jasperStatusList
     * @return
     * @throws PendingException
     */
   public  void batchSave(List<JasperStatus> jasperStatusList) throws PendingException{
       try {
			 jasperStatusMapper.batchInsertSelective(jasperStatusList);
		} catch (Exception e) {
			error("批量保存记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "批量保存记录失败");
	    }
   }
     /**
     * 根据主键查询记录
     * @param id
     * @return
     * @throws PendingException
     */
    public JasperStatus selectByPrimaryKey(Integer id) throws PendingException{
        try {
			return jasperStatusMapper.selectByPrimaryKey(id);
		} catch (Exception e) {
			error("查询记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询记录失败");
	    }
    }
    
     /**
     * 根据条件查询记录列表
     * @param jasperStatus
     * @return
     * @throws PendingException
     */
    public  List<JasperStatus> selectList(JasperStatus jasperStatus) throws PendingException{
       try {
			return jasperStatusMapper.selectList(jasperStatus);
		} catch (Exception e) {
			error("查询列表失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询列表失败");
	    }
    }
    /**
     * 根据Example查询记录列表
     * @param jasperStatusExample
     * @return
     * @throws PendingException
     */
    public  List<JasperStatus> selectListByExample(JasperStatusExample jasperStatusExample) throws PendingException{
       try {
			return jasperStatusMapper.selectListByExample(jasperStatusExample);
		} catch (Exception e) {
			error("根据Example查询记录列表", e);
			throw new PendingException(SysCode.DB_ERROR, "根据Example查询记录列表");
	    }
    }    
    /** 
	 * 分页查询信息
	 * 
	 * @param jasperStatusPageRequestDto
	 * @return
	 * @throws PendingException
	 */
	public PageInfo<JasperStatus> getJasperStatusByPage(JasperStatusPageRequestDto jasperStatusPageRequestDto)
			throws PendingException {
		try {
			PageHelper.startPage(jasperStatusPageRequestDto.getPageNo(),jasperStatusPageRequestDto.getPageSize());
			List<JasperStatus> list=jasperStatusMapper.selectList(jasperStatusPageRequestDto.getJasperStatus());
			PageInfo<JasperStatus> pageInfo = new PageInfo<>(list);
			return pageInfo;
		}catch (Exception e) {
			error("分页查询失败", e);
			throw new PendingException(SysCode.DB_ERROR, "分页查询失败");
		}
	}
    
    /**
     * 根据主键列表查询记录
     * @param ids
     * @return
     * @throws PendingException
     */
    public  List<JasperStatus> selectListByIds(List<Integer> ids) throws PendingException{
        try {
			return jasperStatusMapper.selectListByIds(ids);
		} catch (Exception e) {
			error("根据ID列表批量查询记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据ID列表批量查询记录失败");
	    }
    }
   /**
     * 根据条件查询一条记录
     * @param jasperStatus
     * @return
     * @throws PendingException
     */
    public  JasperStatus selectOne(JasperStatus jasperStatus) throws PendingException{
        try {
			return jasperStatusMapper.selectOne(jasperStatus);
		} catch (Exception e) {
			error("查询单条记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询单条记录失败");
	    }
    }
    
     /**
     * 根据条件查询一条记录 没有记录则抛异常
     * @param jasperStatus
     * @return
     * @throws PendingException
     */
    public  JasperStatus mustGet(JasperStatus jasperStatus) throws PendingException{
      try {
            JasperStatus queryJasperStatus = jasperStatusMapper.selectOne(jasperStatus);
			if(queryJasperStatus==null){
			   throw new PendingException(SysCode.DB_ERROR, "没有查询到相关记录");
			}
			return queryJasperStatus;
		} catch (Exception e) {
			error("查询单条记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询单条记录失败");
	    }
    }
    
     /**
     * 根据Example查询记录总数
     * @param jasperStatusExample
     * @return
     * @throws PendingException
     */
    public  Integer countByExample(JasperStatusExample jasperStatusExample) throws PendingException{
      try {
            return jasperStatusMapper.countByExample(jasperStatusExample);
		} catch (Exception e) {
			error("根据Example查询记录总数失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据Example查询记录总数失败");
	    }
    }

    /**
     * 根据主键修改记录
     * @param jasperStatus
     * @return
     * @throws PendingException
     */
    public JasperStatus updateByPrimaryKey(JasperStatus jasperStatus) throws PendingException{
       try {
			 jasperStatusMapper.updateByPrimaryKey(jasperStatus);
			return jasperStatus;
		} catch (Exception e) {
			error("根据主键更新单条记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据主键更新单条记录失败");
	   }
    }
    /**
     * 根据Example修改记录
     * @param jasperStatus
     * @return
     * @throws PendingException
     */
    public JasperStatus updateByExample(JasperStatus jasperStatus,JasperStatusExample jasperStatusExample) throws PendingException{
       try {
			 jasperStatusMapper.updateByExampleSelective(jasperStatus,jasperStatusExample);
			return jasperStatus;
		} catch (Exception e) {
			error("根据Example修改记录失败", e);
			throw new PendingException(SysCode.DB_ERROR, "根据Example修改记录失败");
	    }
    }
}
